use error_chain::error_chain;
error_chain! {
    errors {
        ReadToEnd(m: String) {
            description("read to end"),
            display("read to end: {}", m),
        }

        CheckFaild(m: String) {
            description("check code failed!"),
            display("check code failed: {}", m),
        }

        BadPack(m: String) {
            description("bad pack"),
            display("bad pack abandon it: {}", m),
        }
    }
}

pub fn error_msg(msg: &str) -> Error {
    Error::from_kind(ErrorKind::Msg(msg.to_string()))
}

pub fn error_read_to_end(msg: &str) -> Error {
    Error::from_kind(ErrorKind::ReadToEnd(msg.to_string()))
}

pub fn error_check_failed(msg: &str) -> Error {
    Error::from_kind(ErrorKind::CheckFaild(msg.to_string()))
}

pub fn error_bad_pack(msg: &str) -> Error {
    Error::from_kind(ErrorKind::BadPack(msg.to_string()))
}
